package com.nxy.cpfsfe.exception;

import com.nxy.cpfsfe.enumtype.RespCd;

/**
 * 业务异常定义
 *  00000  成功
 *  10000  gw
 *  20000  联机
 *  30000  批量
 *  40000  定时
 *
 *  90000  未知异常
 */
public class CpfsBizException extends RuntimeException {

    protected String code;
    protected String msg;

    public CpfsBizException(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public CpfsBizException(String errorMsg, String[] params){
        String[] errors = errorMsg.split("\\|");
        this.code = errors[0];
        this.msg = String.format(errors[1],params);
    }
    
    public CpfsBizException(String errorMsg,String[] params,Throwable cause){
        super(cause);
        String[] errors = errorMsg.split("\\|");
        this.code = errors[0];
        this.msg = String.format(errors[1],params);
    }
    

    public static final String LJ_BIZ_REQ_KEY_DUB="20001|请求流水号[%s]重复[%s]";
    public static final String LJ_BIZ_ACC_DB_DUB="20002|请求流水号[%s]访问数据库表数据异常";
    public static final String LJ_BIZ_SRV_ERR="20003|服务调用失败,报文内容[%s]";
    
    
    public static final String SUCCESS_CODE = RespCd.NCPI0000;
    public static final String SUCCESS_MSG ="交易成功";
    public static final String LOCK_CODE ="000001";
    public static final String LOCK_MSG ="该数据锁定中，请稍后再试";
    public static final String BAT_XML_CHK_FAIL_CODE ="40001";
    public static final String BAT_FTP_DOWN_FAIL_CODE ="40002";
    public static final String BAT_FTP_UPLOAD_FAIL_CODE ="40003";
    public static final String BAT_FTP_DOWN_FAIL_MSG ="文件下载失败";
    public static final String BAT_FTP_UPLOAD_FAIL_MSG ="文件上传失败";
    
    public static final String BAT_BEBATCHREQ_FAIL_CODE ="40004";
    public static final String BAT_BEBATCHREQ_FAIL_MSG ="批量请求表入库失败";
    public static final String BAT_BDBATCHA_FAIL_CODE ="40005";
    public static final String BAT_BDBATCHA_FAIL_MSG ="批量明细表入库失败";
    public static final String BAT_XML_FILE_CHK_FAIL_CODE ="40006";
    
    public static final String TIMER_SMS_SERVICE_CODE ="40007";
    public String  getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static void main(String[] args) {
        try{
            throw new CpfsBizException(CpfsBizException.LJ_BIZ_REQ_KEY_DUB,new String[]{"zzzzzzzzzzzz"});
        }catch (CpfsBizException e){
            System.out.println(e.code+"|"+e.msg);
        }
    }

}
